package com.ruoyi.word.service.impl;

import com.ruoyi.common.domain.word.CommonWord;
import com.ruoyi.common.domain.word.CommonWordSimpleSentence;
import com.ruoyi.word.dao.mapper.CommonWordSimpleSentenceMapper;
import com.ruoyi.word.service.ICommonWordSimpleSentenceService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommonWordSimpleSentenceServiceImpl implements ICommonWordSimpleSentenceService {

    @Autowired
    private CommonWordSimpleSentenceMapper dao;

    @Override
    public int saveByWord(CommonWord word, List<CommonWordSimpleSentence> sentenceList) {
        dao.deleteByWid(word.getId());
        if(CollectionUtils.isEmpty(sentenceList)) {
            return 0;
        }
        sentenceList.stream().forEach(r -> {
            dao.insertSelective(r);
        });
        return 1;
    }

    @Override
    public List<CommonWordSimpleSentence> findByWid(Long wid) {
        return dao.findByWord(wid);
    }

    @Override
    public int deleteByWid(Long wid) {
        return dao.deleteByWid(wid);
    }
}
